package cn.jbooter.mq.autoconfigure.rocketmq.coms;

import java.util.List;

import org.apache.rocketmq.client.producer.MessageQueueSelector;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * int queue选择器:整型队列选择器
 * @author HeJian
 *
 */
public class RocketSelectMessageQueueByIntSelector implements MessageQueueSelector {
	private static final Logger logger = LoggerFactory.getLogger(RocketSelectMessageQueueByIntSelector.class);
	
	
	@Override
	public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
		int intSelector = Integer.valueOf(arg+"");
		logger.info("queue selector arg : {}" ,arg);
		int size = mqs.size();
		logger.info("queue size : {}",size);
		int index = intSelector % size;
		MessageQueue queue = mqs.get(index);
		logger.info("selected queue : mqs[{}] , queue id : {} ",index,queue.getQueueId());
		return queue;
	}

}
